#include<iostream>
#include<string>
#include<vector>


size_t Spilit(const std::string &src, const std::string &sep, std::vector<std::string> *arry)
    {
        size_t offset = 0;
        while (offset < src.size())
        {
            auto pos = src.find(sep, offset); // 在src字符串偏移量offset处，开始向后查找sep字符/字串，返回查找的位置
            if (pos == std::string::npos)//没找到对应字符
            {
                //剩余部分放入arry中
                arry->push_back(src.substr(offset));
                return arry->size();
            }
            if (pos == offset)
            {
                offset = pos + sep.size();
                continue;
            }
            arry->push_back(src.substr(offset, pos - offset));
            offset = pos + sep.size();
        }
        return arry->size();
    };

    int main()
    {
        std::string str="abc,bcd,def,";
        std::vector<std::string> arry;
        Spilit(str,",",&arry);
        for(auto &s:arry)
        {
            std::cout<<"["<<s<<"]\n";
        }

        return 0;
    }